using System;
using System.Security.Cryptography;
using System.Text;

namespace tafei_thingsapi.Utils
{
    public static class SecurityUtils
    {
        public static string Sha256Hex(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                return string.Empty;
            }

            using (var sha256 = SHA256.Create())
            {
                var bytes = Encoding.UTF8.GetBytes(input);
                var hashBytes = sha256.ComputeHash(bytes);
                return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
            }
        }

        public static string Sha256Hex(byte[] input)
        {
            if (input == null || input.Length == 0)
            {
                return string.Empty;
            }

            using (var sha256 = SHA256.Create())
            {
                var hashBytes = sha256.ComputeHash(input);
                return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
            }
        }
    }
} 